<?php
/**
 * Date: 2018/6/29
 * Time: 15:13
 * Author: zeronlee
 */

namespace App\Models\ProjectManage;


use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

class ProjectTaskCount extends Model
{
    protected $table = 'project_task_count';

    protected $fillable = [];

    protected $guarded = [];

    public $timestamps = false;
    /**
     * @return int
     */
    public static function setCount (){
        $year = Carbon::now()->year;
        if (self::getCount($year)){
            return self::where(['year'=>$year])->increment('count');
        }else{
            $data = ['year'=>$year,'count'=>1];
            return intval(self::create($data)->count);
        }
    }

    /**
     * @param $year
     * @return int
     */
    public static function getCount ($year){
        $c = 0;
        if (intval($year))
            $c =self::where(['year'=>$year])->value('count');
        return intval($c);
    }
}